﻿var b = true;
var ArticlePublishId = "";

function Right(c, b) {
    if (b <= 0) {
        return "";
    } else {
        if (b > String(c).length) {
            return c;
        } else {
            var a = String(c).length;
            return String(c).substring(a, a - b);
        }
    }
}

function textCounter(field, cntfield, maxlimit) {
    var charLeft;
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    } else {
        charLeft = maxlimit - field.value.length;
        cntfield.innerHTML = charLeft + " character left";
        if (charLeft == 0) {
            cntfield.style.color = "#FF0000";
        } else {
            cntfield.style.color = "#000";
        }
    }
}

function CreateTag(comResult, textValue, siteId) {
    var txtValue = $('input#' + textValue);

    if (txtValue.length == 0) return;

    var dataString = "txtTagName=" + txtValue.val() + "&SiteID=" + siteId;
    //alert (dataString);return false;
    $.ajax({
            type: "POST",
            url: "/Services/CreateTags.ashx",
            data: dataString,
            success: function(data) {
                if (data == "Error100") {
                    alert("Tên bộ lọc không tồn tại !!");
                } else if (data == "Error101") {
                    alert("Tên bộ lọc quá ngắn !!!!\nXin vui lòng kiểm tra lại.");
                } else if (data == "Error102") {
                    alert("Đã có lỗi xảy ra trong quá trình tạo bộ lọc !!!\nHãy liên hệ với người quản trị để biết thêm chi tiết !!");
                } else {
                    $("#" + comResult).html("");
                    $("#" + comResult).append(data);
                    txtValue.val("");
                }
            }
        });
}


function ChangeStatus(field, vType, vMsg) {
    if (vType == 1) {
        if (field.value == vMsg) {
            field.value = '';
        }
    } else if (vType == 0) {
        if (field.value == '') {
            field.value = vMsg;
        }
    }
}

function getNodeValue(o) {
    try {
        return o.item(0).firstChild.nodeValue;
    } catch(err) {
        return '';
    }
}

function Trim(str) {
    if (str == '')
        return str;
    return RTrim(LTrim(str));
}

function LTrim(str) {
    if (str == '')
        return str;
    return str.replace( /^\s+/ , '');
}

function RTrim(str) {
    if (str == '')
        return str;
    return str.replace( /\s+$/ , '');
}

function IsAlphabet(digit) {
    return /^[a-zA-Z]$/ .test(digit);
}

function Money2Long(input) {
    return input.replace( /\./ig , "");
}

function filterElement(elem) {
    return document.getElementById(elem);
}

function Money_CheckCorrect(controlCheckCorrectId) {
    var input = Trim(filterElement(controlCheckCorrectId).value.toString());

    if (input != '' && !IsAlphabet(input)) {
        var priceFor = Trim(Money2Long(input));
        if (FormatCurrency(priceFor, 'vi-vn', true, true) == "0") {
            filterElement(controlCheckCorrectId).value = '0';
        } else {
            filterElement(controlCheckCorrectId).value = FormatCurrency(priceFor, 'vi-vn', true, true);
        }
    } else {
        filterElement(controlCheckCorrectId).value = input.substring(0, input.length - 1);
    }
}

function FormatCurrency(num, currencyCode, isReplace, justFormat) {
    if (num == null)
        return "";
    num = num.toString().replace( /\$|\,/g , '');
    if (isNaN(num))
        num = "0";
    var sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    var cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
        switch (Trim(currencyCode.toLowerCase())) {
        case 'en-us':
            {
                num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
                break;
            }
        case 'vi-vn':
            {
                num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
                break;
            }
        }
    }
    var res = '0';
    switch (Trim(currencyCode.toLowerCase())) {
    case 'en-us':
        {
            if (justFormat != null && justFormat == true) {
                if (isReplace == false)
                    res = (((sign) ? '' : '-') + num + '.' + cents);
                else
                    res = (((sign) ? '' : '-') + num);
            } else {
                if (isReplace == false)
                    res = (((sign) ? '' : '-') + '$' + num + '.' + cents);
                else
                    res = (((sign) ? '' : '-') + '$' + num);
            }
            break;
        }
    case 'vi-vn':
        {
            if (justFormat != null && justFormat == true) {
                if (isReplace == false)
                    res = (((sign) ? '' : '-') + num + ',' + cents);
                else
                    res = (((sign) ? '' : '-') + num);
            } else {
                if (isReplace == false)
                    res = (((sign) ? '' : '-') + num + ',' + cents + '<u>đ</u>');
                else
                    res = (((sign) ? '' : '-') + num + '<u>đ</u>');
            }
            break;
        }
    }
    return res;
}

var RSS = {
    init: function(vUrl, vItem, vDivId) {
        AjaxRequest.get(
            {
                "url": vUrl,
                'onLoading': function() { gmobj(vDivId).innerHTML = "<div class=\"loadingDiv\">Loading ...</div>"; },
                'onSuccess': function(req) {
                    var title = "";
                    var link = "";
                    var postdate = "";
                    var strOut = "";

                    strOut = "<table cellpadding=\"4\" cellspacing=\"6\" border=\"0\" width=\"100%\" class=\"tblDashboard\">";
                    for (var i = 0; i <= vItem; i++) {
                        title = getNodeValue(req.responseXML.getElementsByTagName('item').item(i).getElementsByTagName('title'));
                        link = getNodeValue(req.responseXML.getElementsByTagName('item').item(i).getElementsByTagName('link'));
                        postdate = getNodeValue(req.responseXML.getElementsByTagName('item').item(i).getElementsByTagName('pubDate'));

                        strOut += "  <tr>";
                        strOut += "      <td><a href=\"".concat(link).concat("\" title=\"").concat(title).concat("\">").concat(title).concat("</a><span class=\"lblPostDate\"> - ").concat(dateFormat(postdate, "fullDate")).concat("</span></td>");
                        strOut += "  </tr>";
                    }
                    strOut += "</table>";
                    gmobj(vDivId).innerHTML = strOut;
                },
                'onError': function(req) {
                    gmobj(vDivId).innerHTML = req.statusText;
                }
            });
    }
};
var Dashboard = {
    getTop5Comment: function(vId) {
        try {
            AjaxRequest.get(
                {
                    "url": "/Services/Dashboard.ashx?action=Top5Comments",
                    'onLoading': function() { gmobj(vId).innerHTML = "<div class=\"loadingDiv\">Loading ...</div>"; },
                    'onSuccess': function(req) {
                        //gmobj(vId).innerHTML = req.responseText;
                        var strContent = "";
                        var strTemp = "";
                        var vUserId = "";
                        var vImageName = "";
                        var vImageNameUnicode = "";
                        var vImageUrl = "";
                        var vCommentBody = "";
                        var vImageDate = "";
                        var vImageId = "";
                        var imageUrlTemp = "";
                        var vImageIdUser = "";
                        if (req.responseText == "NoData") {
                            gmobj(vId).style.display = "No Data";
                        } else {
                            strContent = req.responseXML;
                            var totalItem = strContent.getElementsByTagName('Item').length;

                            if (totalItem > 0) {
                                strTemp = strTemp.concat("<table cellpadding=\"4\" cellspacing=\"6\" width=\"100%\">");
                                for (var i = 0; i < 5; i++) {
                                    vUserId = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('UserID'));
                                    vImageName = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('ImageName'));
                                    vImageNameUnicode = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('ImageNameUnicode'));
                                    vImageUrl = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('ImageUrl'));
                                    vCommentBody = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('CommentBody'));
                                    vImageDate = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('ImageDate'));
                                    vImageId = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('ImageID'));
                                    vImageIdUser = getNodeValue(strContent.getElementsByTagName('Item').item(i).getElementsByTagName('ImageIDUser'));

                                    var d = new Date(vImageDate);
                                    imageUrlTemp = "/Files/" + vImageIdUser + "/" + d.getFullYear() + "/" + Right("00" + (d.getMonth() + 1), 2) + "/" + Right("00" + d.getDate(), 2) + "/";

                                    strTemp = strTemp.concat("    <tr>");
                                    strTemp = strTemp.concat("       <td colspan=\"2\" style=\"font-size:11px;color:#666;\">").concat("From<b> ").concat(vUserId).concat("</b> on <a style=\"color:#21759B;\" target=\"_blank\" href=\"/Home/Photo/Detail/").concat(vImageId).concat("-").concat(vImageName).concat("\">").concat(vImageNameUnicode).concat("</a></td>");
                                    strTemp = strTemp.concat("    </tr>");
                                    strTemp = strTemp.concat("    <tr style=\"border-bottom:solid 1px #CCC;\">");
                                    strTemp = strTemp.concat("       <td style=\"width:75px;\" vAlign=\"top\"><a target=\"_blank\" href=\"/Home/Photo/Detail/").concat(vImageId).concat("-").concat(vImageName).concat("\"><img style=\"border:solid 1px #CCC;padding:1px;\" alt=\"\" src=\"" + imageUrlTemp + "75x0__").concat(vImageUrl).concat("\" /></a></td>");
                                    strTemp = strTemp.concat("       <td vAlign=\"top\" style=\"font-size:11px;\">").concat(vCommentBody).concat("</td>");
                                    strTemp = strTemp.concat("   </tr>");
                                    if (i != 4) {
                                        strTemp = strTemp.concat("<tr>");
                                        strTemp = strTemp.concat("      <td colspan=\"2\"><hr  style=\"color:#CCC;\" width=\"100%\"></td>");
                                        strTemp = strTemp.concat("</tr>");
                                    }
                                }
                                // alert(vImageUrl);
                                strTemp = strTemp.concat("</table>");
                                strTemp = strTemp.concat("<div class=\"major-publishing-actions\"><input type=\"button\" onclick=\"javascript:location.href='/Inside/Comments.aspx'\" value=\"Verify Comment\" style=\"background-color: rgb(33, 117, 155); width: 120px;\" class=\"button\" name=\"btnVerify\"><input type=\"button\" onclick=\"javascript:location.href='/Inside/Comments.aspx?action=Published'\" value=\"Publish Comment\" style=\"background-color: rgb(33, 117, 155); width: 120px;\" class=\"button\" name=\"btnPublish\"></div>");
                                gmobj(vId).innerHTML = strTemp;
                            } else {
                                gmobj(vId).innerHTML = "<div class=\"loadingDiv\">No data found ...</div>";
                            }
                        }
                    },
                    'onError': function(req) { gmobj(vId).innerHTML = req.statusText; }
                });
        } catch(err) {
            return "";
        }
    },
    getStatics: function(vId) {
        try {
            AjaxRequest.get(
                {
                    "url": "/Services/Dashboard.ashx?action=Activity",
                    'onLoading': function() { gmobj(vId).innerHTML = "<div class=\"loadingDiv\">Loading ...</div>"; },
                    'onSuccess': function(req) {
                        //gmobj(vId).innerHTML = req.responseText; 
                        var strContent = "";
                        var strTemp = "";
                        var TotalComment0 = "";
                        var TotalComment1 = "";
                        var TotalImages0 = "";
                        var TotalImages1 = "";
                        var TotalImages2 = "";
                        var TotalUser0 = "";
                        var TotalUser1 = "";

                        if (req.responseText == "NoData") {
                            gmobj(vId).style.display = "No Data";
                        } else {
                            strContent = req.responseXML;
                            // gmobj(vId).innerHTML = req.responseText; 
                            TotalComment = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalComment'));
                            TotalComment0 = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalComment0'));
                            TotalComment1 = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalComment1'));
                            TotalImages = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalImages'));
                            TotalImages0 = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalImages0'));
                            TotalImages1 = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalImages1'));
                            TotalImages2 = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalImages2'));
                            TotalUser = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalUser'));
                            TotalUser0 = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalUser0'));
                            TotalUser1 = getNodeValue(strContent.getElementsByTagName('Item').item(0).getElementsByTagName('TotalUser1'));
                            //alert(TotalUser0);
                            strTemp = strTemp.concat("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" class=\"tblDashboard\">");
                            strTemp = strTemp.concat(" <tr>");
                            strTemp = strTemp.concat("     <td style=\"width:5%;text-align:right;\"><a href=\"Photo.aspx\" class=\"number\">").concat(TotalImages).concat("</a></td>");
                            strTemp = strTemp.concat("     <td style=\"width:20%;\"><a href=\"Photo.aspx\">Photos</a></td>");
                            strTemp = strTemp.concat("     <td style=\"width:40%;\">&nbsp;</td>");
                            strTemp = strTemp.concat("     <td style=\"width:10%;text-align:right;\"><a href=\"Comments.aspx\" class=\"number\">").concat(TotalComment).concat("</a></td>");
                            strTemp = strTemp.concat("     <td style=\"width:20%;\"><a href=\"Comments.aspx\">Comments</a></td>");
                            strTemp = strTemp.concat(" </tr>");
                            strTemp = strTemp.concat(" <tr>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\"><a href=\"Photo.aspx?action=Published&Status=PublishPhoto\" class=\"number\">").concat(TotalImages1).concat("</a></td>");
                            strTemp = strTemp.concat("     <td><a href=\"Photo.aspx?action=Published&Status=PublishPhoto\" class=\"Approved\">Published</a></td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\"><a href=\"Comments.aspx?action=Published\" class=\"number\">").concat(TotalComment1).concat("</a></td>");
                            strTemp = strTemp.concat("     <td><a href=\"Comments.aspx?action=Published\" class=\"Approved\">Published</a></td>");
                            strTemp = strTemp.concat(" </tr>");
                            strTemp = strTemp.concat(" <tr>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\"><a href=\"Photo.aspx\" class=\"number\">").concat(TotalImages0).concat("</a></td>");
                            strTemp = strTemp.concat("     <td><a href=\"Photo.aspx\" class=\"Pending\">Verifying</a></td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\"><a href=\"Comments.aspx\" class=\"number\">").concat(TotalComment0).concat("</a></td>");
                            strTemp = strTemp.concat("     <td><a href=\"Comments.aspx\" class=\"Pending\">Verifying</a></td>");
                            strTemp = strTemp.concat(" </tr>");
                            strTemp = strTemp.concat(" <tr>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\"><a href=\"Photo.aspx?action=PendingDelete\" class=\"number\">").concat(TotalImages2).concat("</a></td>");
                            strTemp = strTemp.concat("     <td><a href=\"Photo.aspx?action=PendingDelete\" class=\"Deleting\">Pending Delete</a></td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\">&nbsp;</td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat(" </tr>");
                            strTemp = strTemp.concat(" <tr>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\"><a href=\"UserManager.aspx\" class=\"number\">").concat(TotalUser).concat("</a></td>");
                            strTemp = strTemp.concat("     <td><a href=\"UserManager.aspx\">Users</a></td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\">&nbsp;</td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat(" </tr>");
                            strTemp = strTemp.concat(" <tr>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\"><a href=\"#\" class=\"number\">").concat(TotalUser1).concat("</a></td>");
                            strTemp = strTemp.concat("     <td><a href=\"#\" class=\"Approved\">Actived</a></td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat("     <td style=\"text-align:right;\">&nbsp;</td>");
                            strTemp = strTemp.concat("     <td>&nbsp;</td>");
                            strTemp = strTemp.concat(" </tr>");
                            strTemp = strTemp.concat(" <tr>");
                            strTemp = strTemp.concat("     <td class=\"last\" style=\"text-align:right;\"><a href=\"#\" class=\"number\">").concat(TotalUser0).concat("</a></td>");
                            strTemp = strTemp.concat("     <td class=\"last\"><a href=\"#\" class=\"Pending\">InActive</a></td>");
                            strTemp = strTemp.concat("     <td class=\"last\">&nbsp;</td>");
                            strTemp = strTemp.concat("     <td class=\"last\" style=\"text-align:right;\">&nbsp;</td>");
                            strTemp = strTemp.concat("     <td class=\"last\">&nbsp;</td>");
                            strTemp = strTemp.concat(" </tr>");
                            strTemp = strTemp.concat("</table>");
                            gmobj(vId).innerHTML = strTemp;
                        }
                    },
                    'onError': function(req) { gmobj(vId).innerHTML = req.statusText; }
                });
        } catch(err) {
            return "";
        }
        return "";
    }
};
var Util = {
    CheckAll: function(chk) {
        var i;
        if (b) {
            for (i = 0; i < chk.length; i++) {
                chk[i].checked = true;
            }
            b = false;
        } else {
            for (i = 0; i < chk.length; i++) {
                chk[i].checked = false;
            }
            b = true;
        }
    },
    ConfirmDeleteArticle: function(vMsg) {
        if (confirm("You are about to delete this post '" + vMsg + "'\nCancel to stop, OK to delete.")) {
            return true;
        } else {
            return false;
        }
    },
    ConfirmDeleteTag: function(vMsg) {
        if (confirm("You are about to delete this tag '" + vMsg + "'\nCancel to stop, OK to delete.")) {
            return true;
        } else {
            return false;
        }
    },
    DisplayPostAction: function(vId) {
        gmobj(vId).style.display = "";
    },
    HidePostAction: function(vId) {
        gmobj(vId).style.display = "none";
    },
    PublishConfirmAction: function() {
        var month = parseInt(gmobj("mmmm").value);
        var day = parseInt(gmobj("dd").value);
        var year = parseInt(gmobj("yy").value);
        var hh = parseInt(gmobj("hh").value);
        var mn = parseInt(gmobj("mn").value);
        var ss = parseInt(gmobj("ss").value);
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        var sOut = "";
        var ampm = "";

        if (hh > 23) {
            hh = 0;
        }
        if (mn > 59) {
            mn = 0;
        }
        if (month < 1 || month > 12) {
            month = 12;
        }
        if (day < 1 || day > 31) {
            day = 31;
        }
        if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
            month--;
        }
        if (ss > 59) {
            ss = 59;
        }
        if (hh > 12) {
            hh = hh - 12;
            ampm = "PM";
        } else if (hh == 12) {
            ampm = "PM";
        } else {
            ampm = "AM";
        }
        if (month == 2) {
            if (day > 29 || (day == 29 && !isleap)) {
                day = 28;
            }
        }
        sOut = month.toString() + "/" + day.toString() + "/" + year.toString() + " " + hh.toString() + ":" + mn.toString() + ":" + ss.toString() + " " + ampm;
        gmobj("txtReleaseDate").value = sOut;
        gmobj(ArticlePublishId).style.display = "none";
        gmobj("PublishInfo").innerHTML = "Schedule for: <b>" + dateFormat(sOut, "mmm d, yyyy") + " @ " + dateFormat(sOut, "HH:MM") + "</b>";
        gmobj("lnkEditDatePublish").style.display = "";
        gmobj("mmmm").value = month.toString();
        gmobj("dd").value = day.toString();
        gmobj("yy").value = year.toString();
        gmobj("hh").value = hh.toString();
        gmobj("mn").value = mn.toString();
        gmobj("ss").value = ss.toString();
    },
    CancelArticlePublish: function() {
        gmobj(ArticlePublishId).style.display = "none";
        gmobj("lnkEditDatePublish").style.display = "";
    },
    EditArticlePublish: function(vId) {
        gmobj(vId).style.display = "";
        gmobj("lnkEditDatePublish").style.display = "none";
        ArticlePublishId = vId;
    },
    ConfirmAction: function(vId) {
        if (gmobj("txtArticlePublic").checked) {
            gmobj("lnkEdit").style.display = "";
            gmobj("ArticleVisibility").innerHTML = "Public";
            gmobj(vId).style.display = "none";
            gmobj("txtArticlePwd").value = "";
            gmobj("txtPostVisible").value = "0";
        } else if (gmobj("txtArticlePassword").checked) {
            gmobj("lnkEdit").style.display = "";
            gmobj("ArticleVisibility").innerHTML = "Password Protected";
            gmobj(vId).style.display = "none";
            gmobj("txtPostVisible").value = "1";
        } else if (gmobj("txtArticlePrivate").checked) {
            gmobj("lnkEdit").style.display = "";
            gmobj("ArticleVisibility").innerHTML = "Private";
            gmobj(vId).style.display = "none";
            gmobj("txtArticlePwd").value = "";
            gmobj("txtPostVisible").value = "2";
        }
    },
    CancelArticleVisible: function(vId) {
        gmobj(vId).style.display = "none";
        gmobj("lnkEdit").style.display = "";
        switch (gmobj("txtPostVisible").value) {
        case "0":
            gmobj("txtArticlePublic").checked = true;
            break;
        case "1":
            gmobj("txtArticlePassword").checked = true;
            break;
        case "2":
            gmobj("txtArticlePrivate").checked = true;
            break;
        }
    },
    ArticlePublic: function() {
        gmobj("frmArticlePwd").style.display = "none";
        gmobj("txtArticlePwd").value = "";
    },
    ArticlePrivate: function() {
        gmobj("frmArticlePwd").style.display = "none";
        gmobj("txtArticlePwd").value = "";
    },
    ArticlePassword: function() {
        gmobj("frmArticlePwd").style.display = "";
    },
    EditArticleVisible: function(vId) {
        gmobj(vId).style.display = "";
        gmobj("lnkEdit").style.display = "none";
        if (gmobj("txtPostVisible").value == "1") {
            gmobj("frmArticlePwd").style.display = "";
        }
    },
    DisplayAction: function(vId) {
        gmobj("row-actions-" + vId).style.display = "";
    },
    HideAction: function(vId) {
        gmobj("row-actions-" + vId).style.display = "none";
    },
    doCol: function() {
        if (b) {
            gmobj("commentct").style.display = "none";
            b = false;
        } else {
            gmobj("commentct").style.display = "";
            b = true;
        }
    },
    ContactUs: function(strLink) {
        window.open(strLink, 'Toasoan', 'height=740px,width=780px,status=no,toolba=no,location=no');
    },
    GoTo: function(strLink) {
        location.href = strLink;
    },
    writeDate: function() {
        var d = new Date();
        var today = d.getDate();
        var thisyear = d.getFullYear();
        var thismonth = d.getMonth() + 1;
        //alert(d.)
        var weekday = new Array("Chủ nhật", "Thứ hai", "Thứ ba", "Thứ tư", "Thứ năm", "Thứ sáu", "Thứ bảy");
        document.write(weekday[d.getDay()] + ", Ngày " + today + " tháng " + thismonth + " năm " + thisyear);
    },
    VnMode: function(id) {
        if (b) {
            document.images[id].src = "/justin/images/vnfont.gif";
            document.images[id].alt = "Tiếng Việt";
            setTypingMode(1);
            b = false;
        } else {
            document.images[id].src = "/justin/images/enfont.gif";
            document.images[id].alt = "Tiếng Anh";
            setTypingMode(0);
            b = true;
        }
    }
};
var Menus = {
    DisplaySubMenu: function(id) {
        gmobj(id).style.display = '';
        gmobj("tg" + id.toString().replace("menu-", "").replace("-2", "")).className = "wp-menu-toggle-selected";
        gmobj("tg" + id.toString().replace("menu-", "").replace("-2", "")).removeAttribute("onclick", "");
        gmobj("tg" + id.toString().replace("menu-", "").replace("-2", "")).setAttribute("onclick", "javascript:Menus.HideSubMenu('" + id + "');");
    },
    HideSubMenu: function(id) {
        gmobj(id).style.display = 'none';
        gmobj("tg" + id.toString().replace("menu-", "").replace("-2", "")).className = "wp-menu-toggle";
        gmobj("tg" + id.toString().replace("menu-", "").replace("-2", "")).removeAttribute("onclick", "");
        gmobj("tg" + id.toString().replace("menu-", "").replace("-2", "")).setAttribute("onclick", "javascript:Menus.DisplaySubMenu('" + id + "');");
    },
    ChangeSelectedMenu: function(id) {
        var vStyle = "";
        var Temp = "";
        var Temp2 = "";
        switch (id.toString().replace("menu-", "").replace("-2", "")) {
        case "0":
            vStyle = "dashboard";
            break;
        case "1":
            vStyle = "posts";
            break;
        case "2":
            vStyle = "media";
            break;
        case "3":
            vStyle = "link";
            break;
        case "4":
            vStyle = "page";
            break;
        case "5":
            vStyle = "cm";
            break;
        }

        for (var i = 0; i < 3; i++) {
            if (i == id.toString().replace("menu-", "").replace("-2", "")) {
                Temp2 = gmobj("menu-" + i + "-1").className.toString().replace("-normal", "");
                gmobj("menu-" + i + "-0").className = vStyle + "Selected";
                gmobj("menu-" + i + "-1").className = Temp2;
            } else {
                Temp = gmobj("menu-" + i + "-0").className.toString().replace("Selected", "Normal");
                Temp2 = gmobj("menu-" + i + "-1").className.toString().toString().replace("-normal", "") + "-normal";
                gmobj("menu-" + i + "-0").className = Temp;
                gmobj("menu-" + i + "-1").className = Temp2;
            }
        }
    }
};
var Tags = {
    ShowTag: function(id) {
        if (b) {
            gmobj(id).style.display = '';
            b = false;
        } else {
            gmobj(id).style.display = 'none';
            b = true;
        }
    },
    AddThisTag: function(TagName) {
        var tagvalue = gmobj("ctl00_ctph_txtTag").value;
        if (tagvalue.length < 1) {
            tagvalue = TagName.replace(" ", "");
        } else {
            tagvalue += "," + TagName.replace(" ", "");
        }
        gmobj("ctl00_ctph_txtTag").value = tagvalue;
        gmobj("ctl00_ctph_txtTag").focus();
    }
};

function gmobj(mtxt) {
    if (document.getElementById) {
        m = document.getElementById(mtxt);
    } else if (document.all) {
        m = document.all[mtxt];
    } else if (document.layers) {
        m = document[mtxt];
    }
    return m;
}

function echeck(str) {

    var at = "@";
    var dot = ".";
    var lat = str.indexOf(at);
    var lstr = str.length;
    var ldot = str.indexOf(dot);
    if (str.indexOf(at) == -1) {
        return false;
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false;
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false;
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false;
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false;
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false;
    }

    if (str.indexOf(" ") != -1) {
        return false;
    }
    return true;
}

function vote_poll(the_form) {
    width = 550;
    height = 250;
    top_val = (screen.height - height) / 2 - 30;
    if (top_val < 0) {
        top_val = 0;
    }
    left_val = (screen.width - width) / 2;

    window.open('', the_form.name, "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + width + ",height=" + height + ", top=" + top_val + ",left=" + left_val);
    the_form.submit();
}

function openImage(vLink, vHeight, vWidth) {
    var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

    if (sLink == '') {
        return false;
    }

    winDef = 'status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,fullscreen=yes,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
    winDef = winDef.concat('top=').concat((screen.height - vHeight) / 2).concat(',');
    winDef = winDef.concat('left=').concat((screen.width - vWidth) / 2);
    newwin = open('', '_blank', winDef);
    newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
    newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" border=0></a>');
    newwin.document.writeln('</body>');

    if (typeof(vLink.href) != 'undefined') {
        return false;
    }
}

function openWin(linkID, w, h) {
    width = w;
    height = h;
    top_val = (screen.height - height) / 2 - 30;
    if (top_val < 0) {
        top_val = 0;
    }
    left_val = (screen.width - width) / 2;

    //linkID+="?id="+id;
    window.open(linkID, null, "toolbar=0,location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=" + width + ",height=" + height + ", top=" + top_val + ",left=" + left_val);
    //the_form.submit();
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {
    // public method for url encoding
    encode: function(string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode: function(string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        string = string.replace( /\r\n/g , "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            } else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            } else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            } else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            } else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
};

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

var dateFormat = function() {
    var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g ,
        timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g ,
        timezoneClip = /[^-+\dA-Z]/g ,
        pad = function(val, len) {
            val = String(val);
            len = len || 2;
            while (val.length < len) val = "0" + val;
            return val;
        };

    // Regexes and supporting functions are cached through closure
    return function(date, mask, utc) {
        var dF = dateFormat;

        // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
        if (arguments.length == 1 && (typeof date == "string" || date instanceof String) && ! /\d/ .test(date)) {
            mask = date;
            date = undefined;
        }

        // Passing date through Date applies Date.parse, if necessary
        date = date ? new Date(date) : new Date();
        if (isNaN(date)) throw new SyntaxError("invalid date");

        mask = String(dF.masks[mask] || mask || dF.masks["default"]);

        // Allow setting the utc argument via the mask
        if (mask.slice(0, 4) == "UTC:") {
            mask = mask.slice(4);
            utc = true;
        }

        var _ = utc ? "getUTC" : "get",
            d = date[_ + "Date"](),
            D = date[_ + "Day"](),
            m = date[_ + "Month"](),
            y = date[_ + "FullYear"](),
            H = date[_ + "Hours"](),
            M = date[_ + "Minutes"](),
            s = date[_ + "Seconds"](),
            L = date[_ + "Milliseconds"](),
            o = utc ? 0 : date.getTimezoneOffset(),
            flags = {
                d: d,
                dd: pad(d),
                ddd: dF.i18n.dayNames[D],
                dddd: dF.i18n.dayNames[D + 7],
                m: m + 1,
                mm: pad(m + 1),
                mmm: dF.i18n.monthNames[m],
                mmmm: dF.i18n.monthNames[m + 12],
                yy: String(y).slice(2),
                yyyy: y,
                h: H % 12 || 12,
                hh: pad(H % 12 || 12),
                H: H,
                HH: pad(H),
                M: M,
                MM: pad(M),
                s: s,
                ss: pad(s),
                l: pad(L, 3),
                L: pad(L > 99 ? Math.round(L / 10) : L),
                t: H < 12 ? "a" : "p",
                tt: H < 12 ? "am" : "pm",
                T: H < 12 ? "A" : "P",
                TT: H < 12 ? "AM" : "PM",
                Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
                o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
                S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
            };

        return mask.replace(token, function($0) {
            return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
        });
    };
}();

// Some common format strings
dateFormat.masks = {
    "default": "ddd mmm dd yyyy HH:MM:ss",
    shortDate: "m/d/yy",
    mediumDate: "mmm d, yyyy",
    longDate: "mmmm d, yyyy",
    fullDate: "dddd, mmmm d, yyyy",
    shortTime: "h:MM TT",
    mediumTime: "h:MM:ss TT",
    longTime: "h:MM:ss TT Z",
    isoDate: "yyyy-mm-dd",
    isoTime: "HH:MM:ss",
    isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
    isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
    dayNames: [
        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
        "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
    ],
    monthNames: [
        "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
        "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
    ]
};

// For convenience...
Date.prototype.format = function(mask, utc) {
    return dateFormat(this, mask, utc);
};